import format from '@dfeidao/atom-web/dt/format';
import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import set_node_cls from '@dfeidao/atom-web/ui/set-node-cls';
import show from '@dfeidao/atom-web/ui/show';
import p001 from './p001';
import p002 from './p002';
import p003 from './p003';
import p004 from './p004';
export default async function a001(fd: IFeidaoAiBrowserComponent, no: string) {
	// todo
	const a = fd.data.node.querySelector<HTMLDivElement>('[data-id="update"]');
	set_node_cls(a, 'display-n', false);
	const res = await nodejs<Array<{
		record_no: string, project_name: string, inventory_time: number,
		customer_reviews: string, lnventory_name: string, inventory_people: string
	}>>('inventory-of-assets/zj-000003/s001', { record_no: no });


	const project_name1 = fd.data.node.querySelector<HTMLSpanElement>('[data-id="project_name"]');
	project_name1.textContent = res[0].project_name;

	const inventory_time1 = fd.data.node.querySelector<HTMLSpanElement>('[data-id="inventory_time"]');
	const time = format(res[0].inventory_time, 0);
	inventory_time1.textContent = time;

	const inventory_people1 = fd.data.node.querySelector<HTMLSpanElement>('[data-id="inventory_people"]');
	inventory_people1.textContent = res[0].inventory_people;

	// const customer_reviews1 = fd.data.node.querySelector<HTMLImageElement>('[data-id="customer_reviews"]');
	// customer_reviews1.textContent = res[0].customer_reviews;
	// console.log("签名", res[0].customer_reviews);

	const lnventory_name1 = fd.data.node.querySelector<HTMLSpanElement>('[data-id="lnventory_name"]');
	lnventory_name1.textContent = res[0].lnventory_name;

	const ff = await nodejs<{ dt: Array<{}>; c: number }>('inventory-of-assets/zj-000003/s002', { record_no: no });

	const dataNo = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p001"]');
	const data = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p002"]');
	const dataf = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p002"]');
	if (ff.dt.length > 0) {
		render(fd, ff.dt, p001, 'p001', 'inner');
		data.style.display = "none";
		dataNo.style.display = "block";
	} else {
		render(fd, '', p002, 'p002', 'inner');
		dataNo.style.display = "none";
		data.style.display = "block";
	}
	if (ff.dt.length > 20) {
		render(fd, ff.dt, p003, 'p003', 'inner');
		dataf.style.display = "block";
	} else {
		dataf.style.display = "none";
	}
	show(fd.data.node);
	render(fd, res[0].customer_reviews, p004, 'p004', 'inner');
}
